package org.lcp.gatlingqueue.multithread;

import java.io.IOException;
import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;

import org.lcp.gatlingqueue.interfaces.GatlingQueue;

@SuppressWarnings("rawtypes")
public class MyThread implements Runnable {

	private GatlingQueue queue;

	private int countStart = 0;

	private CyclicBarrier cb;

	public MyThread(GatlingQueue queue, int countStart, CyclicBarrier cb)
			throws IOException {
		this.queue = queue;
		this.countStart = countStart;
		this.cb = cb;
	}

	@Override
	public void run() {
		for (int i = countStart; i <= countStart + 9; i++) {
			queue.fire(i);
		}
		try {
			int i = cb.await();
			System.out.println(System.currentTimeMillis() + ":"
					+ Thread.currentThread().getName() + ":" + i);
		} catch (InterruptedException e) {
			e.printStackTrace();
		} catch (BrokenBarrierException e) {
			e.printStackTrace();
		}
	}
}
